# -*- coding: utf -8 -*-

import math
import random

"""
a = '0xa'
b = '0xb'

base = 16
a_int = int ( a , base )
b_int = int ( b , base )

print a_int
print b_int


c_int = a_int + b_int

c = hex (c_int)

print c

b = '0b11110001'

print hex (int (b , 2))
"""
"""
c = 3 + 6j

print c , '\n' , c.imag , '\n' , c.real

a = c.real
b = c.imag

r = math.sqrt (a ** 2 + b ** 2)
print "modulo = {0}".format(r)


r = (a**2 + b**2) ** 0.5
print "modulo = {0}".format(r)

t = math.atan2(b,a)

print t * 180. / math.pi

print math.atan2 (-2, -2), math.atan2(2,2)
print math.atan(-2/-2), math.atan(2/2)
"""
"""
l1 = [2 ,2 ,3 ,4]
l2 = ["sjfdlkjsdljf","kjslfdsj"]
l3 = [l1 , l2]
l4 = list ( "Uma  carrada de erres" )

print l4

s5 = ''

for x in l4:
	if x == 'r':
		pass
	else:
		s5 += x
		pass
	pass

print s5

s6 = reduce ( lambda x, y: x + y , filter (lambda x: x!= 'r' ,l4))

print s6
"""
"""
l1 = list ()
N = 20
k = 0 
while k < N:
	l1.append(random.randint(0,99))
	k+=1
	pass 
	
l2 = list()

for x in l1:
	if not (x % 2) :
		l2.append(x)
		pass
	pass
l1 = [random.randint (0,99) for k in range (N)]
print "l1:" , l1
l2 = filter(lambda x : not (x % 2) , l1 )
print "l2:" , l2
"""
"""
def serie_iter(n):
	
	k = 0
	soma = 0.0
	
	while k <= n:
		soma += 1.0 / (2.0 ** k)
		k += 1
		pass
	return soma
	
def serie_fun(n):
	if n==0:
		return 1.0
	else:
		return 1.0 / (2.0 ** n) + serie_fun ( n-1)

def serie_fun2(n):
	return reduce (lambda x, k: x + 1.0 / (2.0 ** k) , range ( 0 , n +1))

for k in range (21):
	print k, serie_iter(k), serie_fun(k), serie_fun2(k)
"""

def soma_integral(f,a,b):
	N = 500
	
	dx = (float (b) - float(a)) / float(N)
	
	soma = 0.0
	x = a
	while x <= b:
		soma += f(x) * dx
		x += dx
		pass
	return soma

def f(x):
	return x

a = 0.0
b = 1.0
print soma_integral(f,a,b)	

	
